package com.settlement.system.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.settlement.system.common.base.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
* <p>
* 天猫平台订单
* </p>
*
* @author huangrensen
* @since 2024-05-09
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class TmOrder extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
    * ID
    */
    private String id;
    @TableField(exist = false)
    private List<String> pIdList;


    /**
    * 店铺ID
    */
    private Long storeId;
    @TableField(exist = false)
    private String storeName;


    /**
    * 子订单编号
    */
    private String sourcePreformSubNo;


    /**
    * 主订单编号
    */
    private String sourcePreformMainNo;
    @TableField(exist = false)
    private List<String> sourcePreformMainNoList;


    /**
    * 标题
    */
    private String title;


    /**
    * 价格
    */
    private BigDecimal price;


    /**
    * 购买数量
    */
    private Integer qty;


    /**
    * 外部系统编号
    */
    private String systemNo;


    /**
    * 商品属性
    */
    private String productInfo;


    /**
    * 套餐信息
    */
    private String pack;


    /**
    * 联系方式备注
    */
    private String remark;


    /**
    * 订单状态
    */
    private String status;


    /**
    * 商家编码
    */
    private String sellerCode;


    /**
    * 支付单号
    */
    private String payNo;


    /**
    * 买家应付货款
    */
    private BigDecimal totalAmount;


    /**
    * 买家实际支付金额
    */
    private BigDecimal actTotalAmount;


    /**
    * 退款状态
    */
    private String returnStatus;


    /**
    * 退款金额
    */
    private String returnAmount;


    /**
    * 订单创建时间
    */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderCreateTime;


    /**
    * 订单付款时间
    */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime orderPayTime;


    /**
    * 商品id
    */
    private String productId;


    /**
    * 分阶段订单信息
    */
    private String partInfo;


    /**
    * 备注标签
    */
    private String remarkTag;


    /**
    * 商家备注
    */
    private String sellerRemark;


    /**
    * 主订单买家留言
    */
    private String buyerRemark;


    /**
    * 发货时间
    */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime sendTime;


    /**
    * 物流单号
    */
    private String transportNo;


    /**
    * 物流公司
    */
    private String transportCompany;


    /**
    * 是否赔付
    */
    private String indemnity;


    /**
    * 赔付金额
    */
    private String indemnityAmount;


    /**
    * 赔付出账时间
    */
    private String indemnityBillTime;

    @TableField(exist = false)
    private String billMonth;

    @TableField(exist = false)
    private String tableName;

    // 截取长度超出范围的字段
    public void cutString() {
        if (this.title != null && this.title.length() > 100) {
            this.title = this.title.substring(0, 100);
        }
        if (this.productInfo != null && this.productInfo.length() > 2000) {
            this.productInfo = this.productInfo.substring(0, 2000);
        }
        if (this.pack != null && this.pack.length() > 100) {
            this.pack = this.pack.substring(0, 100);
        }
        if (this.remark != null && this.remark.length() > 500) {
            this.remark = this.remark.substring(0, 500);
        }
        if (this.partInfo != null && this.partInfo.length() > 100) {
            this.partInfo = this.partInfo.substring(0, 100);
        }
        if (this.remarkTag != null && this.remarkTag.length() > 100) {
            this.remarkTag = this.remarkTag.substring(0, 100);
        }
        if (this.sellerRemark != null && this.sellerRemark.length() > 2000) {
            this.sellerRemark = this.sellerRemark.substring(0, 2000);
        }
        if (this.buyerRemark != null && this.buyerRemark.length() > 2000) {
            this.buyerRemark = this.buyerRemark.substring(0, 2000);
        }
    }
}
